package com.ebook.ui.sync;

import com.ebook.database.dao.BookReadDataDao;
import com.ebook.database.dao.CategoryDao;
import com.ebook.database.dao.LoginUserDao;
import com.ebook.entity.User;
import com.ebook.service.BookService;
import com.ebook.service.UserService;
import com.ebook.service.implement.BookServiceImpl;
import com.ebook.ui.workspace.EBookWebPool;
import com.ebook.ui.workspace.EBookWebView;
import com.ebook.ui.workspace.WorkSpace;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;


public class WorkSyncer {
    public static WorkSpace workSpace;
    public static EBookWebPool webPool;
    public static EBookWebView webView;

    public static LoginUserDao login;
    public static UserService userService;
    public static BookService bookService;
    public static BookReadDataDao bookReadDataDao;
    public static CategoryDao categoryDao;
    public static User loginUser;

    public static ClassPathXmlApplicationContext sp = new ClassPathXmlApplicationContext("beans.xml");
    public WorkSyncer() throws NoSuchFieldException, IllegalAccessException {
        initialize();
    }
    public void initialize() throws NoSuchFieldException, IllegalAccessException {
        login = WorkSyncer.sp.getBean("login",LoginUserDao.class);
        userService = WorkSyncer.sp.getBean("userService",UserService.class);
        if(login.getLoginUserId()==null){
            loginUser = null;
        }else{
            loginUser = userService.selectUserByUserId(login.getLoginUserId());
//            System.out.println(loginUser);
        }
        bookService = sp.getBean("bookService", BookServiceImpl.class);
        bookReadDataDao = sp.getBean("readData",BookReadDataDao.class);
        categoryDao = sp.getBean("categoryDao",CategoryDao.class);
        webView = new EBookWebView();
        webPool = new EBookWebPool(webView);
        workSpace = new WorkSpace(webPool);
        webPool.initWebPool();
        webView.initWebView();
        webView.syncActivitySize();

    }
}
